package com.spring.test.springdemo;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.PayloadApplicationEvent;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;

/**
 * @author yuantongqin
 * @date 2018/8/10 下午2:27
 */
public class Multicaster {

    public static void main(String[] args) {


        ApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster();
        //添加监听器
        multicaster.addApplicationListener(new ApplicationListener<ApplicationEvent>() {
            @Override
            public void onApplicationEvent(ApplicationEvent event) {
                System.out.println("监听到事件了："+event);
            }
        });
        //发布一个事件
        multicaster.multicastEvent(new PayloadApplicationEvent<Object>("1","hello world"));

    }
}
